#!/bin/bash

#Check if the correct # of options are given
if [ ! $# == 2 ]; then
  echo "Usage: $0 input output"
  exit 1
fi

#Tests if the input file exists
if ! test -f $1; then
	echo "Specified input file does not exist: " $1
	exit 1
fi

#test if the meta-env is accessible on the path
if [ -z `which sglr` ]; then
	echo "sglr not found in path: " $PATH
	exit 1
fi

PARSETABLE=$2".pt"
echo "Generating the parse table:" $PARSETABLE
sglr -p ../src/main/resources/pico.tbl -i $1 -o $PARSETABLE

echo "Generating Abstract syntax tree:" $2
implodePT -t -i $PARSETABLE -o $2

echo "Cleaning up parse table:" $PARSETABLE
rm $PARSETABLE
 